Skip to content

Conversation

@PookieBuns
Copy link
Contributor

  1. update _init_.py file so import can now be found using from sqlmodel.ext.asyncio import AsyncSession which obeys the import format of sqlalchemy Add documentation about how to use the async tools (session, etc) #626 (comment)
  2. add tests to AsyncSession utilizing testcontainers and asyncpg. This could introduce overhead for further testing because it requures a docker container to be spun up
  3. add a create_async_engine function to match its non async port of create_engine

Doesn't really address the documentation part of #626 but adds a few QOL features and sets up an easy testing framework for async features

@PookieBuns

This comment was marked as resolved.

@tiangolo tiangolo added the feature New feature or request label Oct 22, 2023
@github-actions
Copy link
Contributor

📝 Docs preview for commit af84d75 at: https://5fc91ef2.sqlmodel.pages.dev

@PookieBuns

This comment was marked as resolved.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2023

📝 Docs preview for commit fb60073 at: https://f6ad04c2.sqlmodel.pages.dev

@peidrao
Copy link

peidrao commented Nov 19, 2023

Fix conflicts

@github-actions
Copy link
Contributor

📝 Docs preview for commit 3e9bfd8 at: https://c7b5a1e8.sqlmodel.pages.dev

@darkandrew7 darkandrew7 mentioned this pull request Feb 4, 2024
9 tasks
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2025

This pull request has a merge conflict that needs to be resolved.

Copy link
Member

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PookieBuns, thanks for your interest and efforts!

This looks a bit raw and contains changes that are not necessary (testcontainers).

Would you like to continue working on this?


# create_async_engine by default already has future set to be true.
# Porting this over to sqlmodel to make it easier to use.
def create_async_engine(*args: Any, **kwargs: Any) -> AsyncEngine:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we don't have autocompletion and type hints for parameters

Comment on lines +50 to +52
testcontainers = "^3.7.1"
psycopg2-binary = "^2.9.7"
asyncpg = "^0.28.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be good idea in general to introduce testcontainers and test SQLModel with real Postgres, but for the reasons of this PR I think we can just use aiosqlite driver and in-memory DB

assert hero_create == hero_query


def test_async_create(postgres_container_url: str) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to use @pytest.mark.anyio to run async tests: https://anyio.readthedocs.io/en/stable/testing.html

Comment on lines +21 to +26
# SQLModel.metadata is a singleton and the Hero Class has already been defined.
# If I flush the metadata during this test, it will cause test_enum to fail
# because in that file, the model isn't defined within a function. For now, the
# workaround is to set extend_existing to True. In the future, test setup and
# teardown should be refactored to avoid this issue.
__table_args__ = {"extend_existing": True}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can clear DB before each test, that's common approach.
Or, use in-memory SQLite DB with aiosqlite driver

@PookieBuns
Copy link
Contributor Author

I will re-open this over the weekend. It's been a while 😂

@github-actions github-actions bot removed the waiting label Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants